# -*- coding:utf-8 -*-
import models, service, web
from baseHandler import BaseHandler
from utils.decorator import render

class CreateCompanyCase(BaseHandler):
    @render('createCompanyCase.html')
    def GET(self, branchCompanyId):
        user = self.getCurrentUser()
        branchCompanyId = long(branchCompanyId)
        service.Company.getBranchCompany(branchCompanyId)
        hasOverviewRight = service.User.hasOverviewRight(user)

        if not hasOverviewRight and branchCompanyId != user.company_id:
            raise web.seeother('/create/company/%d/case' % user.company_id)

        branchCompanys = models.Company.getBatchByType(models.Company.TYPE_BRANCH) if hasOverviewRight else [models.Company.getById(user.company_id)]
        return {'title' : u'创建案件', 'branch_companys' : branchCompanys, 'active_company_id' : branchCompanyId, 'active_type' : 'create', 'can_overview' : hasOverviewRight}